package com.physics.mps.module.comsol.builder.comp;

import com.physics.mps.module.comsol.builder.Builder;

/**
 * @author mcsoft
 * @date 2023/10/16 09:37
 * @description comsol java 模型组件脚本构建
 */
public class CompBuilder {
    
    private final Builder builder;
    
    
    public CompBuilder(Builder builder) {
        this.builder = builder;
    }



    /**
     * 脚本生成
     * @param compTag
     */
    public void build(String compTag) {
        String modelTag = builder.uniqueTag("Model");
        buildModel(modelTag, compTag);
    }


    /**
     * 构建模型
     * @param modelTag
     * @param compTag
     */
    public void buildModel(String modelTag, String compTag) {
        // 创建模型
        builder.change(1, 2);
        builder.append("Model model = ModelUtil.create(");
        builder.value(modelTag);
        builder.append(");");

        // modelPath
        builder.change(1, 2);
        builder.append("model.modelPath(");
        builder.value(builder.workspace);
        builder.append(");");

        // 创建组件
        builder.change(1, 2);
        builder.append("ModelNode comp = model.component().create(");
        builder.value(compTag);
        builder.append(");");

    }

    /**
     * 生成创建模型代码
     */
    @Deprecated
    public void buildModel(String modelTag, String compTag, String geomTag, String meshTag) {

        // 创建模型
        builder.change(1, 2);
        builder.append("Model model = ModelUtil.create(");
        builder.value(modelTag);
        builder.append(");");

        // modelPath
        builder.change(1, 2);
        builder.append("model.modelPath(");
        builder.value(builder.workspace);
        builder.append(");");

        // 创建组件
        builder.change(1, 2);
        builder.append("ModelNode comp = model.component().create(");
        builder.value(compTag);
        builder.append(");");

        // 创建组件几何
        builder.change(1, 2);
        builder.append("GeomSequence geom = comp.geom().create(");
        builder.value(geomTag);
        builder.append(", 3);");

        // 创建组件网格
        builder.change(1, 2);
        builder.append("comp.mesh().create(");
        builder.value(meshTag);
        builder.append(");");


    }




}
